package net;

import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

public class SocketTest {

    @Test
    public void testSocket() throws IOException {
        Socket socket = new Socket("localhost", 8888);
        OutputStream outputStream = socket.getOutputStream();
        outputStream.write("跟磊哥学习java如何".getBytes());
        System.out.println("客户端给服务端发送数据成功");

        InputStream inputStream = socket.getInputStream();
        byte[] buff = new byte[1024];
        int readLength = inputStream.read(buff);
        System.out.println("服务端返回的内容是:"+new String(buff, 0, readLength));
        socket.close();
    }
}
